from datetime import datetime

from sqlalchemy import DateTime, ForeignKey, String
from sqlalchemy.orm import Mapped, mapped_column, relationship

from app.db.base_class import BaseEntity


class AuthSession(BaseEntity):
  __tablename__ = "auth_sessions"

  user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), index=True)
  refresh_token: Mapped[str] = mapped_column(String(512), unique=True, index=True)
  expires_at: Mapped[datetime] = mapped_column(DateTime(timezone=True))
  user_agent: Mapped[str | None] = mapped_column(String(255))
  ip_address: Mapped[str | None] = mapped_column(String(64))

  user: Mapped["User"] = relationship(lazy="joined")
